-- Wabtec Railway Electronics - Proprietary and Confidential Information
// This script assumes the train has been fully initialized properly,
// and that it is headed in an arbitrary direction at an arbitrary speed

// Forked from Movement authority through the entire territory_Loop_CBTC_v8.ts
// Script has been modified to include provisions for real office


start
// This script assumes the train is moving in an arbitrary direction 
// and at an arbitrary speed

//////// Test Parameters
// Parameters for TMC2
// float LoopPostLow = 217 // KP for low end of the test boundary
// float LoopPostHigh = 239.5// KP for high end of the test boundary
// float SRPostLow = 217  // KP for low end of speed-restricted area
// float SRPostHigh= 218 // KP for high end of speed-restricted area

// Parameters for TMC3
float LoopPostLow = 241 // KP for low end of the test boundary
float LoopPostHigh = 250// KP for high end of the test boundary
float SRPostLow = 241  // KP for low end of speed-restricted area
float SRPostHigh = 242 // KP for high end of speed-restricted area

float NominalSpeed = 40// The nominal speed
float RestrictedSpeed = 35// The restricted speed
float SlewTime = 15// The slew time for MC_SLEW_SPEED function
int SubDiv = 100 // The SubDiv we're operating on. Comment out this line if you want an argument to initialize this. (i.e. use the line below)
// int SubDiv = argv1// The SubDiv we're operating on. Comment out this line if you want to initialize the value in this .TS file. (i.e. use the line above)
int DebugCounter = 0
int LogDumpCounter = 0

string LoopPostHigh_String
string LoopPostLow_String
ftoa(LoopPostLow, LoopPostLow_String, 4)
ftoa(LoopPostHigh, LoopPostHigh_String, 4)
float LoopPostLowBuffer = LoopPostLow  + 1.1 * 0.5 * (NominalSpeed * SlewTime) / (60 * 60) // Create a buffer zone for slewing to a stop. Using kinematic equation distance = 0.5 * (v_final + v_initial) * time. Then increase by 10% to add a little padding
float LoopPostHighBuffer = LoopPostHigh - 1.1 * 0.5 * (NominalSpeed * SlewTime) / (60 * 60) // Create a buffer zone
float PrevPost = 0

int DebugKPSpeedInterval = 15 // in seconds
int LogDumpInterval = 10 * 60 // in seconds
int LoopWaitTime = 500 // in milliseconds
int DebugCounterTrip = DebugKPSpeedInterval * 1000 / LoopWaitTime
int LogDumpCounterTrip = LogDumpInterval * 1000 / LoopWaitTime

reset_output
test 
title Movement authority through the entire territory

-> Training Scripts.11
status 0

gosub reset_test_bench

-- Purpose
-- The on-board functionality of Movement authority through the entire 
-- territory (P1-07 to the KM 0.0) at MAS

-> Initialize the onboard and bring it to DISENGAGED state
action
-> Position the train near Starting KP on MainTrack1 heading south-bound 
-| in decreasing track direction in SteelLine (100).
status
LOCO::mc_set_location_mp(100, LoopPostLow_String, 1)
LOCO::mc_set_track_direction(tdINCREASING)
wait 1000
status 0
-> Observe the train is at MP 285.000 on MainTrack1.
//verify
-> Select location as Main Track, Ignore if already selected
action

gosub StartOfTrack

// -> Verify signal authority at next switch
// verify
-> Increasing train speed to Nominal [over a 10 second 
-| period].
status

gosub SlowToRestricted
status 0

// OFFICE::01021_SEND // Will change this to a ASK DISPATCHER FOR 1021 if needed

@Loop1
// print ("(LOCO::mc_milepost > SRPostLow): %s  | (PrevPost < SRPostLow): %s", (LOCO::mc_milepost > SRPostLow),(PrevPost < SRPostLow)) // debug print

// The following 4 lines of code currently have a "1 ||" in the latter part of the if statement in case we want to check the speed at a later point. Right now, it's basically OR'd away by the 1 ||
// Obey speed restriction when traveling in increasing direction
if ( (LOCO::mc_milepost >= SRPostLow) && (PrevPost <= SRPostLow) && (1 || (LOCO::mc_speed_kph == NominalSpeed) ) ) gosub SlowToRestricted //: print ("Diff = %s", LOCO::mc_milepost - PrevPost)
if ( (LOCO::mc_milepost >= SRPostHigh) && (PrevPost <= SRPostHigh) && (1 || (LOCO::mc_speed_kph == RestrictedSpeed) ) ) gosub SpeedToNominal

// Obey speed restriction when traveling in decreasing direction
if ( (LOCO::mc_milepost <= SRPostHigh) && (PrevPost >= SRPostHigh) && (1 || (LOCO::mc_speed_kph == NominalSpeed) ) ) gosub SlowToRestricted
if ( (LOCO::mc_milepost <= SRPostLow) && (PrevPost >= SRPostLow) && (1 || (LOCO::mc_speed_kph == RestrictedSpeed) ) ) gosub SpeedToNominal

// Warp back to beginning
if ((LOCO::mc_milepost >= LoopPostHighBuffer) && (PrevPost < LoopPostHighBuffer)) gosub HyperJumpBackToBeginningLow
if ((LOCO::mc_milepost <= LoopPostLowBuffer) && (PrevPost > LoopPostLowBuffer)) gosub HyperJumpBackToBeginningHigh

set PrevPost = LOCO::mc_milepost

set DebugCounter += 1
set LogDumpCounter += 1

// Every 15 seconds, output KP and Speed
if (DebugCounter == DebugCounterTrip) gosub PrintKPAndSpeed

// Every 10 minutes, dump logs
if (LogDumpCounter == LogDumpCounterTrip) gosub DumpIntermediateLog
if (LogDumpCounter == LogDumpCounterTrip) set LogDumpCounter = 0

wait LoopWaitTime
if (1) gosub Loop1

@test_done
gosub close_test_bench
end //save_output "output\Training Scripts.11_se"

///////////////////// BEGIN LOOPING SUBROUTINES


@SlowToRestricted
LOCO::MC_SLEW_SPEED_KPH(RestrictedSpeed, SlewTime)
print ("KP = %s, Spd = %s | [SlowToRestricted] Slewing Speed to RESTRICTED = %s at KP %s, in Time = %s", LOCO::mc_milepost, LOCO::mc_speed_kph, RestrictedSpeed, LOCO::mc_milepost, SlewTime)
wait SlewTime * 1000
return

@SpeedToNominal
LOCO::MC_SLEW_SPEED_KPH(NominalSpeed, SlewTime)
print ("KP = %s, Spd = %s | [SpeedToNominal] Slewing Speed to NOMINAL = %s at KP %s, in Time = %s", LOCO::mc_milepost, LOCO::mc_speed_kph, NominalSpeed, LOCO::mc_milepost, SlewTime)
wait SlewTime * 1000
return

@HyperJumpBackToBeginningLow
print ("KP = %s, Spd = %s | [HyperJumpBackToBeginningLow] Hyperjumping back to beginning (low)", LOCO::mc_milepost, LOCO::mc_speed_kph)
gosub SlewTrainToStop
LOCO::MC_SET_LOCATION_MP(SubDiv, LoopPostLow_String, 1) //LOCO::MC_SET_TRACK_DIRECTION(tdINCREASING)
wait 15000
print ("Hyperjumped back to KP %s", LOCO::mc_milepost) //print ("Direction changed to INCREASING at KP %s", LOCO::mc_milepost)
wait 5000
// gosub StartOfTrack
wait 10000
//OFFICE::01021_SEND // Will change this to a ASK DISPATCHER FOR 1021 if needed
//OFFICE::01090_SEND
wait 6000

// Hit Appropriate Keys on Display Server to Override the Exception
DISPLAY1::PRESS_KEY(0) //ACCEPT
wait 5000
//DISPLAY1::PRESS_KEY(0) //ACCEPT
//wait 5000
// DISPLAY1::PRESS_KEY(0) //ACCEPT
// wait 5000
// DISPLAY1::PRESS_KEY(0) //ACCEPT
// wait 5000

gosub SlowToRestricted

//Dump an output file, since we've just completed a run down the track

gosub DumpFinalLogs
return

@HyperJumpBackToBeginningHigh
print ("KP = %s, Spd = %s | [HyperJumpBackToBeginningHigh] Hyperjumping back to beginning (high)", LOCO::mc_milepost, LOCO::mc_speed_kph)
gosub SlewTrainToStop
LOCO::MC_SET_LOCATION_MP(SubDiv, LoopPostHigh_String, 1) //LOCO::MC_SET_TRACK_DIRECTION(tdINCREASING)
wait 15000
print ("Hyperjumped back to KP %s", LOCO::mc_milepost) //print ("Direction changed to INCREASING at KP %s", LOCO::mc_milepost)
wait 5000
// gosub StartOfTrack
wait 10000
//OFFICE::01021_SEND // Will change this to a ASK DISPATCHER FOR 1021 if needed
//OFFICE::01090_SEND
wait 6000

// Hit Appropriate Keys on Display Server to Override the Exception
DISPLAY1::PRESS_KEY(0) //ACCEPT
wait 5000
// DISPLAY1::PRESS_KEY(0) //ACCEPT
// wait 5000
// DISPLAY1::PRESS_KEY(0) //ACCEPT
// wait 5000
// DISPLAY1::PRESS_KEY(0) //ACCEPT
// wait 5000

gosub SlowToRestricted

//Dump an output file, since we've just completed a run down the track

gosub DumpFinalLogs
return

@SlewTrainToStop
LOCO::MC_SLEW_SPEED_KPH(0,SlewTime)
print("KP = %s, Spd = %s | [SlewTrainToStop] Slewing Train to Stop at KP %s, in Time = %s", LOCO::mc_milepost, LOCO::mc_speed_kph, LOCO::mc_milepost, SlewTime)
wait SlewTime * 1000
wait 10000
return

///////////////////// CLERICAL SUBROUTINES

@DumpFinalLogs
print("END OF RUN. Dumping log.")
save_output "output\InfLoop_Final"
reset_output

SLICE1::DBG_LOG_SAVE_CURRENT_WTS("output\InfLoop_Final.rtf")
SLICE1::DBG_LOG_CLEAR_CURRENT
return

@DumpIntermediateLog
print("LOG DUMP INTERVAL OF %s SECONDS REACHED. Dumping intermediate log.", LogDumpInterval)
save_output "output\InfLoop_Intermediate"
SLICE1::DBG_LOG_SAVE_CURRENT_WTS("output\InfLoop_Intermediate.rtf")
return

@PrintKPAndSpeed
print("KP = %s, Spd = %s | DEBUG_OUTPUT", LOCO::mc_milepost, LOCO::mc_speed_kph )
set DebugCounter = 0
return

///////////////////// END LOOPING SUBROUTINES

@reset_test_bench
-> Reset the test bench.
status
   gosub open_SLICE1
   gosub open_DISPLAY1
   gosub start_ioc_simulator
   gosub start_loco_simulator
//   gosub start_office_simulator
//   gosub open_wayside_simulator
status 0
   return

@close_test_bench
-> Close the test bench.
status
   gosub close_SLICE1
   gosub close_DISPLAY1
   gosub stop_ioc_simulator
   gosub reset_loco_simulator_route
//   gosub stop_office_simulator
//   gosub reset_wayside_simulator
status 0
   return

@open_SLICE1
   if_connected(SLICE1) : gosub connect_SLICE1
   if_connected(SLICE1) : gosub manual_connect_SLICE1
   if_connected(SLICE1) : return

-> SLICE1 Debug Client connected.
status
   SLICE1::DBG_LOG_CLEAR_CURRENT()
   SLICE1::DBG_LOG_START_SAVE_WTS("output\DebugClientConnect_s1.rtf")
   SLICE1::GET_BUILD_DATE()
   wait 500
status 0
   return

@connect_SLICE1
-> Connecting SLICE1.
status
   connect SLICE1
wait 7000
status 0
   return

@manual_connect_SLICE1
-> SLICE1: Not Connected - If Script Engine cannot be connected, start 
-| saving the log file to: 'output\Training Scripts.11_s1.rtf'
action
   return

@close_SLICE1
   if_connected(SLICE1) : goto manual_close_SLICE1
   SLICE1::DBG_LOG_STOP_SAVE
   return

@manual_close_SLICE1
-> SLICE1: Not Connected - Stop saving the log file.
action
   return

@open_DISPLAY1
   if_connected(DISPLAY1) : gosub connect_DISPLAY1
   if_connected(DISPLAY1) : gosub manual_connect_DISPLAY1
   if_connected(DISPLAY1) : return

-> DISPLAY1 Display Server connected.
status
   wait 500
status 0
   return

@connect_DISPLAY1
-> Connecting DISPLAY1.
status
   connect DISPLAY1
wait 1000
status 0
   return

@manual_connect_DISPLAY1
-> DISPLAY1: Not connected. Try connecting with Script Engine.
action
   return

@close_DISPLAY1
   return

@start_ioc_simulator
   if_connected(IOC) : gosub connect_ioc_simulator
   if_connected(IOC) : gosub manual_connect_ioc_simulator
   if_connected(IOC) : return

-> Reset the IOC Simulator.
status
   IOC::GET_VERSION()
   wait 500
status 0
   return

@connect_ioc_simulator
-> Connecting IOC.
status
   connect IOC
wait 1000
status 0
   return

@manual_connect_ioc_simulator
-> IOC: Not connected. Try connecting with Script Engine.
action
   return

@stop_ioc_simulator
   return

@start_loco_simulator
   if_connected(LOCO) : gosub connect_loco_simulator
   if_connected(LOCO) : gosub manual_connect_loco_simulator
   if_connected(LOCO) : return

-> Reset the Locomotive Simulator.
status
   LOCO::GET_BUILD_DATE()
   wait 500
   LOCO::MC_SET_SPEED_MPH(0)
   wait 10
   LOCO::MC_RELEASE_BRAKES(TRUE)
   wait 10
   LOCO::MC_SET_REVERSER(rpFORWARD)
   wait 10
   LOCO::TD_SET(TDID_HEADLIGHT_BRIGHT, 1, TRUE)
   wait 10
   LOCO::TD_SET(TDID_EAB_BAIL, 0, TRUE)
   wait 10
   LOCO::TD_SET(TDID_BRK_LVR_SUPP, 0, TRUE)
   wait 10
   LOCO::TD_SET(TDID_CYLINDER_CMD, 0, TRUE)
   wait 10
   LOCO::TD_SET(TDID_EMERG_BRK_CMD, 0, TRUE)
   wait 10
   LOCO::TD_SET(TDID_FLOW, 1, TRUE)
   wait 10
   LOCO::TD_SET(TDID_PTC_CUTOUT, 0, TRUE)
   wait 10
   LOCO::TD_SET(TDID_EAB_LEAD, 1, TRUE)
   wait 10
   LOCO::TD_SET(TDID_EAB_SETUP, 2, TRUE)
   wait 10
   LOCO::SETUP_AUTO_PRESSURES(TRUE)
   wait 10
   LOCO::MC_DB_ON(FALSE)
   wait 10
   LOCO::TD_SET(TDID_PCS_OPEN, 0, TRUE)
   wait 10
   LOCO::TD_SET(TDID_BCP, 0, TRUE)
   wait 10
   LOCO::TD_SET(TDID_FEED_VALVE, 90, TRUE)
   wait 10
   LOCO::TD_SET(TDID_TARGET_ER, 90, TRUE)
   wait 10
   LOCO::TD_SET(TDID_MAIN_RES, 150, TRUE)
   wait 10
   LOCO::TD_SET(TDID_FUEL_GAL, 1000, TRUE)
   wait 10
   LOCO::TD_SET(TDID_TR_EFFORT, 40, TRUE)
   wait 10
   LOCO::TD_SET(TDID_TM_CURRENT, 1, TRUE)
   wait 10
   LOCO::TD_SET(TDID_NOTCH, 0, TRUE)
   wait 10
   LOCO::SETUP_AUTO_NOTCH_ENABLED(TRUE)
   wait 10
   LOCO::TD_SET(TDID_EOT_COMM, 4, TRUE)
   wait 10
   LOCO::SETUP_STOP_SHORT_DISTANCE(500)
   wait 10
   LOCO::SETUP_USE_BRAKING_CURVE(TRUE)
   wait 10
   LOCO::GPS_SET_UNCERTAINTY(0, 0)
   wait 10
   LOCO::GPS2_SET_UNCERTAINTY(0, 0)
   wait 10
   LOCO::GPS_SET_UNCERTAINTY_ALT(0)
   wait 10
   LOCO::GPS2_SET_UNCERTAINTY_ALT(0)
   wait 10
   LOCO::GPS_SET_DRIFT_TYPE(driftNONE)
   wait 10
   LOCO::GPS2_SET_DRIFT_TYPE(driftNONE)
   wait 10
   LOCO::GPS_SET_DRIFT_DISTANCE(0)
   wait 10
   LOCO::GPS2_SET_DRIFT_DISTANCE(0)
   wait 10
   LOCO::GPS_SET_SAT_COUNT(7)
   wait 10
   LOCO::GPS2_SET_SAT_COUNT(7)
   wait 10
   LOCO::SETUP_GPS_ENABLED(TRUE)
   wait 10
   LOCO::SETUP_GPS2_ENABLED(TRUE)
   wait 10
   LOCO::GPS_SET_MANUAL_ECEF(1, 1, 1)
   wait 10
   LOCO::GPS2_SET_MANUAL_ECEF(1, 1, 1)
   wait 10
-> Allow onboard to lose resolution.
status
   wait 9000
status 0
   LOCO::GPS_CLEAR_MANUAL_ECEF()
   wait 10
   LOCO::GPS2_CLEAR_MANUAL_ECEF()
   wait 10
   LOCO::GPS_SET_QUALITY(gpsDGPS)
   wait 10
   LOCO::GPS2_SET_QUALITY(gpsDGPS)
   wait 10
   gosub reset_loco_simulator_route
status 0
   return   // Reset the Loco Simulator.

@connect_loco_simulator
-> Connecting LOCO.
status
   connect LOCO
   wait 6000
status 0
   return

@manual_connect_loco_simulator
-> LOCO: Not connected. Try connecting with Script Engine.
action
   return

@reset_loco_simulator_route
   LOCO::MC_RESET_ALL_SWITCHES
   wait 100
   return

@wait_for_milepost
   if(TIMED_OUT) goto wait_for_milepost_timeout
   if(LOCO::wait_mp_evt_status == -1) goto wait_for_milepost_stopped
   if(LOCO::wait_mp_evt_status == -2) goto wait_for_milepost_wrong_track
   pass Arrived at Milepost
   return

@wait_for_milepost_timeout
   print "Milepost not reached in time."
   fail Arrived at Milepost
   return

@wait_for_milepost_stopped
   fail Arrived at Milepost
   return

@wait_for_milepost_wrong_track
   fail Arrived at Milepost
   return

@start_office_simulator
//   if_connected(OFFICE) : gosub connect_office_simulator_OFFICE
//   if_connected(OFFICE) : gosub manual_connect_office_simulator_OFFICE
//   if_connected(OFFICE) : return

-> Reset the Office Simulator.
status
// OFFICE::LOG_SIM_BUILD_DATE()
// wait 500
// OFFICE::GET_LOCO_NAME()
// wait 250
// OFFICE::02011_GET_ON-BOARD_SOFTWARE_VERSION()
// wait 250

// OFFICE::02000_AUTO_ACK(TRUE)
// OFFICE::02001_AUTO_ACK(TRUE)
// OFFICE::02003_AUTO_ACK(TRUE)
// OFFICE::02005_AUTO_ACK(TRUE)
// OFFICE::02007_AUTO_ACK(TRUE)
// OFFICE::02010_AUTO_ACK(TRUE)
// OFFICE::02011_AUTO_ACK(TRUE)
// OFFICE::02020_AUTO_ACK(TRUE)
// OFFICE::02022_AUTO_ACK(TRUE)
// OFFICE::02030_AUTO_ACK(TRUE)
// OFFICE::02032_AUTO_ACK(TRUE)
// OFFICE::02041_AUTO_ACK(TRUE)
// OFFICE::02050_AUTO_ACK(TRUE)
// OFFICE::02051_AUTO_ACK(TRUE)
// OFFICE::02054_AUTO_ACK(TRUE)
// OFFICE::02061_AUTO_ACK(TRUE)
// OFFICE::02070_AUTO_ACK(TRUE)
// OFFICE::02072_AUTO_ACK(TRUE)
// OFFICE::02081_AUTO_ACK(TRUE)
// OFFICE::02083_AUTO_ACK(TRUE)
// OFFICE::02084_AUTO_ACK(TRUE)
// OFFICE::02085_AUTO_ACK(TRUE)
// OFFICE::02086_AUTO_ACK(TRUE)
// OFFICE::02087_AUTO_ACK(TRUE)
// OFFICE::02088_AUTO_ACK(TRUE)

// -> Reset the SL-01000 message. BOS: 1.
// status
// OFFICE::01000_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01000_DELETE_MSG
// OFFICE::01000_SET_VERIFICATION_STATUS(VS_EMPLOYEE_INFO_VERIFIED)
// OFFICE::01000_SET_EMPLOYEE_IDENTIFIER("DEF-ID")
// OFFICE::01000_SET_EMPLOYEE_FIRST_NAME("Casey")
// OFFICE::01000_SET_EMPLOYEE_MIDDLE_INITIAL("L")
// OFFICE::01000_SET_EMPLOYEE_LAST_NAME("Jones")
// OFFICE::01000_SET_REASON_TEXT("Just a good engineer")
// status 0

// -> Reset the SL-01001 message. BOS: 1.
// status
// OFFICE::01001_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01001_DELETE_MSG
// wait 50
// OFFICE::01001_ADD_TRAIN_IDS("TRAIN DEFAULT")
// wait 50
// status 0

// -> Reset the SL-01003 message. BOS: 1.
// status
// OFFICE::01003_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01003_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01004 message. BOS: 1.
// status
// OFFICE::01004_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01004_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01005 message. BOS: 1.
// status
// // An empty 01005 message should work for initialization.
// // A default message could be loaded manually with the Office Simulator.
// OFFICE::01005_SAVE_MESSAGE
// wait 50
// status 0

// -> Reset the SL-01010 message. BOS: 1.
// status
// OFFICE::01010_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01010_DELETE_MSG
// wait 50
// OFFICE::01010_SET_REASON(RFS_CONFIRM_02010)
// wait 50
// status 0

// -> Reset the SL-01011 message. BOS: 1.
// status
// OFFICE::01011_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01011_DELETE_MSG
// wait 50
// OFFICE::01011_SET_DEPARTURE_TEST_LOCATION_TEXT("Home Depot")
// wait 50
// status 0

// -> Reset the SL-01020 message. BOS: 1.
// status
// OFFICE::01020_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01020_DELETE_MSG
// wait 50
// OFFICE::01020_SET_POLL_RATE(3)
// wait 50
// status 0

// -> Reset the SL-01030 message. BOS: 1.
// status
// OFFICE::GET_LOCO_NAME()
// wait 100
// OFFICE::01030_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01030_DELETE_MSG
// OFFICE::01030_SET_REASON_FOR_SENDING(RFS_UNSOLICITED3)
// OFFICE::01030_SET_LEAD_LOCOMOTIVE_ORIENTATION(LLO_FRONT)
// OFFICE::01030_SET_TRAIN_TYPE(TT_FREIGHT)
// // 70 cars * 100 tons/car
// OFFICE::01030_SET_TRAILING_TONNAGE(7000)
// // 1 OB/car
// OFFICE::01030_SET_NUMBER_OF_OPERATIVE_BRAKES(70)
// // 4 axles/car
// OFFICE::01030_SET_NUMBER_OF_AXLES(280)
// // 85 ft/loco + (70 cars * 70 ft/car)
// OFFICE::01030_SET_TRAIN_LENGTH(4985)
// OFFICE::01030_SET_LOADED_CAR_COUNT(70)
// OFFICE::01030_SET_EMPTY_CAR_COUNT(0)
// // Cause the Onboard to calculate total braking force.
// OFFICE::01030_SET_TOTAL_BRAKING_FORCE(30000001)
// // Max speed that allows all subdivs to be used.
// OFFICE::01030_SET_MAXIMUM_TRAIN_SPEED(79)
// wait 250
// // 215 tons, 85 feet, 4400 horsepower; match with Loco Module ID values.
// OFFICE::01030_ADD_LOCOMOTIVE_ITEM(OFFICE::dataLOCO_NAME, 1, 215, LS_RUN, 85, 4400)
// wait 500

// OFFICE::01030_SET_REASON_FOR_SENDING(RFS_RESPONSE_CAD_CONSIST)
// status 0

// -> Reset the SL-01033 message. BOS: 1.
// status
// OFFICE::01033_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01033_DELETE_MSG
// wait 50
// OFFICE::01033_SET_ACKNOWLEDGEMENT_INDICATION(AI_ACK)
// wait 50
// status 0

// -> Reset the SL-01040 message. BOS: 1.
// status
// OFFICE::01040_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01040_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01041 message. BOS: 1.
// status
// OFFICE::01041_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01041_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01043 message. BOS: 1.
// status
// OFFICE::01043_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01043_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01050 message. BOS: 1.
// status
// OFFICE::01050_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01050_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01051 message. BOS: 1.
// status
// OFFICE::01051_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01051_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01053 message. BOS: 1.
// status
// OFFICE::01053_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01053_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01054 message. BOS: 1.
// status
// OFFICE::01054_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01054_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01060 message. BOS: 1.
// status
// OFFICE::01060_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01060_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01061 message. BOS: 1.
// status
// OFFICE::01061_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01061_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01062 message. BOS: 1.
// status
// OFFICE::01062_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01062_DELETE_MSG
// wait 50
// OFFICE::01062_SEND
// wait 250
// status 0

// -> Reset the SL-01070 message. BOS: 1.
// status
// OFFICE::01070_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01070_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01071 message. BOS: 1.
// status
// OFFICE::01071_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01071_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01072 message. BOS: 1.
// status
// OFFICE::01072_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01072_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01073 message. BOS: 1.
// status
// OFFICE::01073_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01073_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01080 message. BOS: 1.
// status
// OFFICE::01080_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01080_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01081 message. BOS: 1.
// status
// OFFICE::01081_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01081_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01082 message. BOS: 1.
// status
// OFFICE::01082_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01082_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01083 message. BOS: 1.
// status
// OFFICE::01083_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01083_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01084 message. BOS: 1.
// status
// OFFICE::01084_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01084_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01085 message. BOS: 1.
// status
// OFFICE::01085_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01085_DELETE_MSG
// wait 50
// OFFICE::01085_SET_ACKNOWLEDGEMENT_INDICATION(AI_ACK)
// wait 50
// status 0

// -> Reset the SL-01086 message. BOS: 1.
// status
// OFFICE::01086_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01086_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01087 message. BOS: 1.
// status
// OFFICE::01087_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01087_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01088 message. BOS: 1.
// status
// OFFICE::01088_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01088_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01089 message. BOS: 1.
// status
// OFFICE::01089_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01089_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01090 message. BOS: 1.
// status
// OFFICE::01090_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01090_DELETE_MSG
// wait 50
// status 0

// -> Reset the SL-01022 message. BOS: 1.
// status
// OFFICE::01022_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01022_DELETE_MSG
// wait 50

// OFFICE::SET_MESSAGE_INSTANCE(01022,1)
// wait 100
// OFFICE::01022_SET_SUBDIVISION/DISTRICT_ID(100)
// wait 100


// -> Reset the SL-01007 message. BOS: 1.
// status
// OFFICE::01007_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01007_DELETE_MSG
// wait 50
// OFFICE::01007_SEND
// wait 250
// status 0

// -> Reset the SL-01021 message. BOS: 1.
// status
// OFFICE::01021_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01090_SEND
// wait 50
// status 0

status 0
   return   // Reset the Office Simulator.

@connect_office_simulator_OFFICE
-> Connecting OFFICE.
// status
   // connect OFFICE
// wait 3000
status 0
   return

@manual_connect_office_simulator_OFFICE
// -> OFFICE: Not connected. Try connecting with Script Engine.
// action
   return

@stop_office_simulator
   return

@open_wayside_simulator
   // if_connected(WAYSIDE) : gosub connect_wayside_simulator
   // if_connected(WAYSIDE) : gosub manual_connect_wayside_simulator
   // if_connected(WAYSIDE) : return

   // WAYSIDE::GET_BUILD_DATE()
   // wait 500
return

@reset_wayside_simulator
-> Reset the Wayside Simulator.
// status
   // WAYSIDE::reset_wayside_devices
   // wait 10
   // WAYSIDE::SET_ACS_ASPECT(acsCLEAR)
   // wait 10
   // WAYSIDE::SET_ATC_ASPECT(atcCLEAR)
   // wait 10
// status 0
   return

@connect_wayside_simulator
// -> Connecting WAYSIDE.
// status
   // connect WAYSIDE
// wait 5000
// status 0
   return

@manual_connect_wayside_simulator
// -> WAYSIDE: Not connected. Try connecting with Script Engine.
// action
   return

@StartOfTrack
-> ASK DISPATCHER to populate SL-01051: Movement Authority Dataset. Number: 
-| 10. Reason: New Authority. Crew Action: No action. Type: Track 
-| warrant. Subdivision: 100. Bidirectional: Subdivision 100 on 
-| MainTrack1 from POST_LOW to POST_HIGH. Control Point in 0 is NA, CP id 0, Object 
-| id 0. BOS: 1.
verify
// OFFICE::SET_MESSAGE_INSTANCE(01051,0)
// wait 50
// OFFICE::01051_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01051_DELETE_MSG_INSTANCE(0)
// wait 50
// OFFICE::01051_SET_REASON(RFS_NEW_AUTHORITY)
// wait 50
// OFFICE::01051_SET_CREW_ACTION_REQUIRED(CAR_NO_ACTION)
// wait 50
// OFFICE::01051_SET_REF_NUM(10)
// wait 50
// OFFICE::01051_SET_AUTHORITY_TYPE(AT_TRACK_WARRANT_AUTHORITY)
// wait 50
// OFFICE::01051_ADD_SUB_DIST_ITEM(100)
// wait 50
// OFFICE::01051_SET_TIMESTAMP(1970, 01, 01, 00, 00, 00)
// wait 50
// OFFICE::01051_ADD_AUTH_ITEM_V2(ASD_BIDIRECTIONAL,2870000,"","",2400000,"","","MainTrack1",100)
// wait 100
// OFFICE::01051_SET_SUB_ID(0)
// wait 50
// OFFICE::01051_SET_SITE_DEVICE_ID("0")
// wait 50
// OFFICE::01051_SET_SITE_NAME("0")
// wait 50
// OFFICE::01051_SET_DEVICE_TYPE(0)
// wait 50
// OFFICE::01051_SET_BODY_OF_SUMMARY_TEXT("Authority: 10 - Track warrant")
// wait 50
// OFFICE::01051_ADD_TEXT_LINES("Track warrant")
// wait 50
// OFFICE::01051_ADD_TEXT_LINES("Bidirectional ,  From: 287 To: 240 Track: MainTrack1 Subdiv: 100")
// wait 50
// OFFICE::01051_SAVE_MESSAGE
// wait 100
// status 0
// OFFICE::01022_DELETE_MSG_INSTANCE(1)
// wait 100
// OFFICE::SET_MESSAGE_INSTANCE(01022,1)
// wait 100
// OFFICE::01022_SET_SUBDIVISION/DISTRICT_ID(100)
// wait 100
// OFFICE::01022_SAVE_MESSAGE
// wait 250
// OFFICE::01021_DELETE_MSG_INSTANCE(0)
// wait 100
// OFFICE::SET_MESSAGE_INSTANCE(1021,0)
// wait 100
// OFFICE::01021_SAVE_MESSAGE
// wait 250
// OFFICE::SET_MESSAGE_INSTANCE(01051,0)
// wait 50
// OFFICE::01051_SEND
// wait 500

-> Waiting 5 seconds to pass authority through messaging system
status
wait 5000      // 5 seconds
status 0

// -> ASK DISPATCHER to populate SL-01051: Movement Authority Dataset. Number: 
// -| 11. Reason: New Authority. Crew Action: No action. Type: Track 
// -| warrant. Subdivision: 100. Bidirectional: Subdivision 100 on 
// -| MainTrack1 from 240 to 208. Control Point in 0 is NA, CP id 0, Object 
// -| id 0. BOS: 1.
// verify
// OFFICE::SET_MESSAGE_INSTANCE(01051,1)
// wait 50
// OFFICE::01051_SET_AUTOPOPULATE(TRUE, "")
// wait 50
// OFFICE::01051_DELETE_MSG_INSTANCE(1)
// wait 50
// OFFICE::01051_SET_REASON(RFS_NEW_AUTHORITY)
// wait 50
// OFFICE::01051_SET_CREW_ACTION_REQUIRED(CAR_NO_ACTION)
// wait 50
// OFFICE::01051_SET_REF_NUM(11)
// wait 50
// OFFICE::01051_SET_AUTHORITY_TYPE(AT_TRACK_WARRANT_AUTHORITY)
// wait 50
// OFFICE::01051_ADD_SUB_DIST_ITEM(100)
// wait 50
// OFFICE::01051_SET_TIMESTAMP(1970, 01, 01, 00, 00, 00)
// wait 50
// OFFICE::01051_ADD_AUTH_ITEM_V2(ASD_BIDIRECTIONAL,2400000,"","",2080000,"","","MainTrack1",100)
// wait 100
// OFFICE::01051_SET_SUB_ID(0)
// wait 50
// OFFICE::01051_SET_SITE_DEVICE_ID("0")
// wait 50
// OFFICE::01051_SET_SITE_NAME("0")
// wait 50
// OFFICE::01051_SET_DEVICE_TYPE(0)
// wait 50
// OFFICE::01051_SET_BODY_OF_SUMMARY_TEXT("Authority: 11 - Track warrant")
// wait 50
// OFFICE::01051_ADD_TEXT_LINES("Track warrant")
// wait 50
// OFFICE::01051_ADD_TEXT_LINES("Bidirectional ,  From: 240 To: 208 Track: MainTrack1 Subdiv: 100")
// wait 50
// OFFICE::01051_SAVE_MESSAGE
// wait 100
// status 0
// OFFICE::01022_DELETE_MSG_INSTANCE(1)
// wait 100
// OFFICE::SET_MESSAGE_INSTANCE(01022,1)
// wait 100
// OFFICE::01022_SET_SUBDIVISION/DISTRICT_ID(100)
// wait 100
// OFFICE::01022_SAVE_MESSAGE
// wait 250
// OFFICE::01021_DELETE_MSG_INSTANCE(0)
// wait 100
// OFFICE::SET_MESSAGE_INSTANCE(1021,0)
// wait 100
// OFFICE::01021_SAVE_MESSAGE
// wait 250
// OFFICE::SET_MESSAGE_INSTANCE(01051,1)
// wait 50
// OFFICE::01051_SEND
// wait 500

// -> Waiting 5 seconds to pass authority through messaging system
// status
// wait 5000      // 5 seconds
// status 0

-> Go to Mandatory directives and check for the 1 Authority
action

// wait 10000

//OFFICE::01090_SEND
return

